import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '@/views/LoginView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: LoginView
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/LoginView.vue')
    },
    {
      path: '/login/common',
      name: 'loginCommon',
      component: () => import('@/views/admin/CommonView.vue')
    },
    {
      path: '/login/traffic',
      name: 'loginTraffic',
      component: () => import('@/views/admin/TrafficView.vue')
    },
    {
      path: '/login/admin',
      name: 'loginAdmin',
      component: () => import('@/views/admin/AdminView.vue')
    },
    {
      path: '/register',
      name:'register',
      component: () => import('@/views/RegisterView.vue')
    },
    {
      path: '/forget',
      name:'forget',
      component: () => import('@/views/ForgetView.vue')
    },
  ],
})

// 路由守卫
// router.beforeEach(async (to,from,next)=>{
//   var auth =localStorage.getItem('token');
//   if(to.path == "/login" || to.path == '/register'){
//     if(auth){
//       router.push("/")
//     }else{
//       next()
//     }
//   }else{
//     if(auth){
//       next();
//     }else{
//       router.push("/login") // 未登录则跳转到登录页面，但用户管理下线时会移除token返回登录出现bug
//     }
//   }
// })

export default router
